import {Modal, ModalFuncProps} from "antd";

const {confirm} = Modal;


export function asyncConfirm(props: ModalFuncProps) {
    return new Promise((resolve, reject) => {
        confirm({
            ...props,
            onOk: async ()  => {
                if (props.onOk){
                    let result =  props.onOk()
                    if (result instanceof Promise){
                        try {
                            await result
                        } catch (e) {
                            reject()
                        }
                    }
                }
                resolve(null)
            },
            onCancel: () => {
                reject()
            }
        })
    });
}